package grape.base.service.user.api;

import grape.base.service.user.dto.UserCreateParam;
import grape.base.service.user.dto.UserThirdCreateParam;
import grape.base.service.user.po.User;
import grape.common.service.common.IBaseService;
import grape.common.service.trans.ITransService;

/**
 * <p>
 * 后台管理用户表 服务类
 * </p>
 *
 * @author yangwei
 * @since 2019-09-23
 */
public interface IUserService extends IBaseService<User>, ITransService<String, String> {

    public static final String trans_type_userNickname ="userNickname";
    public static final String trans_type_userAvatar ="userAvatar";
    /**
     * 添加用户
     * @param cp
     */

    User createUser(UserCreateParam cp);
    /**
     * 仅用于第三方登录添加或更新用户
     * @param cp
     * @return
     */
    User saveOrUpdateUser(UserThirdCreateParam cp);
    @Override
    default boolean support(String type){
        return isEqualAny(type, trans_type_userNickname,trans_type_userAvatar);
    }

    @Override
    default String trans(String type, String key){
        User user = getById(key);
        if (user != null) {
            if(isEqual(type,trans_type_userNickname)){
                return user.getNickname();
            }  else  if(isEqual(type,trans_type_userAvatar)){
                return user.getAvatar();
            }
        }
        return null;
    }

}
